home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Plotting / aa_Intel_Only / Gnuplot / GnuplotSource / AxesPane.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  9.4 KB  |  426 lines

  1. /*
  2.  *  Copyright (C) 1993  Robert Davis
  3.  *
  4.  *  This program is free software; you can redistribute it and/or
  5.  *  modify it under the terms of Version 2, or any later version, of 
  6.  *  the GNU General Public License as published by the Free Software 
  7.  *  Foundation.
  8.  */
  9.  
  10.  
  11. static char RCSId[]="$Id: AxesPane.m,v 1.10 1993/05/18 03:54:40 davis Exp $";
  12.  
  13.  
  14. #import <appkit/Application.h>
  15. #import <appkit/Button.h>
  16. #import <appkit/Form.h>
  17. #import <appkit/Matrix.h>
  18. #import <appkit/Panel.h>        /* NXRunAlertPanel()        */
  19. #import <appkit/PopUpList.h>
  20. #import <appkit/Text.h>            /* This Pane is a text delegate    */
  21. #import <appkit/TextFieldCell.h>
  22. #import <appkit/View.h>
  23.  
  24. #import <objc/NXStringTable.h>
  25.  
  26. #import "AxesPane.h"
  27. #import "GnuplotPlot.h"
  28. #import "Status.h"
  29. #import "StatusTics.h"
  30. #import "TicCell.h"
  31. #import "TicObject.h"
  32. #import "TicOptionsPanel.h"
  33.  
  34.  
  35. @interface AxesPane (Private)
  36.  
  37. - _updateLabelIsThreeD:(BOOL)isThreeD;
  38. - _updateTicsIsThreeD:(BOOL)isThreeD;
  39. - _updateRangeIsThreeD:(BOOL)isThreeD isPolar:(BOOL)isPolar;
  40.  
  41. @end
  42.  
  43.  
  44.  
  45. @implementation AxesPane
  46.  
  47.  
  48. - init
  49. {
  50.     [super init];
  51.  
  52.     [NXApp loadNibSection: "AxesPane.nib"
  53.             owner: self
  54.         withNames: NO
  55.          fromZone: [self zone]];
  56.  
  57.     icon = "InspectorAxes.tiff";
  58.  
  59.     return self;
  60. }
  61.  
  62.  
  63. - free
  64. {
  65.     [ticOptionsPanel free];
  66.     return [super free];
  67. }
  68.  
  69.  
  70. /*  
  71.  *  Overridden from Pane.
  72.  */
  73. - selectControl:sender
  74. {
  75.     if ([[rangeAutoMatrix findCellWithTag:X_TAG] state] &&
  76.     [[rangeAutoMatrix findCellWithTag:Y_TAG] state] &&
  77.     [[rangeAutoMatrix findCellWithTag:Z_TAG] state])
  78.  
  79.     [labelMatrix selectText:self];
  80.  
  81.     else
  82.     [rangeMatrix selectText:self];
  83.  
  84.     return self;
  85. }
  86.  
  87.  
  88.  
  89. - (BOOL)updateStatus:aStatus doc:aDoc
  90. {
  91.     id oldStatus = status;
  92.  
  93.     /*  
  94.      *  We only bother updating if status has changed since we last 
  95.      *  updated, or if we just became the current pane (didSwap) -- 
  96.      *  assuming that status and aDoc are non-nil, of course.
  97.      */
  98.  
  99.     if ([super updateStatus:aStatus doc:aDoc]
  100.     && ((status != oldStatus) || didSwap)) {
  101.  
  102.     BOOL isThreeD = [status isThreeD];
  103.     BOOL isPolar = [status isPolar];
  104.     Window *viewWindow;
  105.     id cell;
  106.  
  107.     [(viewWindow = [view window]) disableDisplay];
  108.  
  109.     [axisXButton setState:[status axisCoord:X_TAG]];
  110.     [axisXButton setEnabled:!isThreeD];
  111.     [axisYButton setState:[status axisCoord:Y_TAG]];
  112.     [axisYButton setEnabled:!isThreeD];
  113.     [axisTitleField setTextGray:isThreeD? NX_DKGRAY :NX_BLACK];
  114.  
  115.     /* Grid in 3d plots only show up if there's a border. */ //
  116.     [gridButton setState:[status grid] && !(isThreeD && ![status border])];
  117.     [gridButton setEnabled:!(isThreeD && ![status border])];
  118.  
  119.     [[logMatrix findCellWithTag:X_TAG] setState:[status isLogCoord:X_TAG]];
  120.     [[logMatrix findCellWithTag:Y_TAG] setState:[status isLogCoord:Y_TAG]];
  121.     [cell = [logMatrix findCellWithTag:Z_TAG] setState:
  122.                 [status isLogCoord:Z_TAG] && !isPolar];
  123.     [cell setEnabled:isThreeD];
  124.     [logMatrix display];
  125.     
  126.     [anglesButton setEnabled:isPolar];
  127.     [anglesButton setTitle:[status degrees]? "Degrees" :"Radians"];
  128.  
  129.     [self _updateLabelIsThreeD:isThreeD];
  130.     [self _updateTicsIsThreeD:isThreeD];
  131.     [self _updateRangeIsThreeD:isThreeD isPolar:isPolar];
  132.  
  133.     [viewWindow reenableDisplay];
  134.  
  135.     [self perform:@selector(selectControl:)
  136.          with:self
  137.        afterDelay:1
  138.        cancelPrevious:YES];
  139.  
  140.     didSwap = NO;
  141.     return YES;
  142.  
  143.     }
  144.  
  145.     return NO;
  146. }
  147.  
  148.  
  149. - (BOOL)forceUpdateStatus:aStatus doc:aDoc
  150. {
  151.     BOOL    needsRedisplay;
  152.  
  153.     /* Update ourself first, then the options panel  */
  154.  
  155.     needsRedisplay = [super forceUpdateStatus:aStatus doc:aDoc];
  156.  
  157.     if ([[ticOptionsPanel panel] isVisible])
  158.     [ticOptionsPanel forceUpdate];
  159.  
  160.     return needsRedisplay;
  161. }
  162.  
  163.  
  164. - didSwapIn:sender
  165. {
  166.     [super didSwapIn:self];
  167.     didSwap = YES;
  168.     return self;
  169. }
  170.  
  171.  
  172.  
  173. - doSetRange:sender
  174. {
  175.     int tag = [[sender selectedCell] tag];
  176.     BOOL isPolar = [status isPolar];
  177.  
  178.     double min = [[sender cellAt:tag :0] doubleValue];
  179.     double max = [[sender cellAt:tag :1] doubleValue];
  180.  
  181.     if (min == max)
  182.         NXRunAlertPanel ([stringSet valueForStringKey: "range"],
  183.                          [stringSet valueForStringKey: "zeroRange"],
  184.                          NULL, NULL, NULL);
  185.     else  {
  186.         if (isPolar && (tag == Z_TAG))  tag = R_TAG;
  187.  
  188.         if ([status isLogCoord:tag] && ((min <= 0) || (max <= 0)))
  189.             NXRunAlertPanel ([stringSet valueForStringKey: "log"],
  190.                              [stringSet valueForStringKey: "logRange"],
  191.                              NULL, NULL, NULL);
  192.         else
  193.             [status setRangeCoord:tag min:min max:max];
  194.     }
  195.  
  196.     [self _updateRangeIsThreeD:[status isThreeD] isPolar:isPolar];
  197.     return self;
  198. }
  199.  
  200.  
  201. - doSetRangeAuto:sender
  202. {
  203.     Window *win;
  204.     id cell = [sender selectedCell];
  205.     int tag = [cell tag];
  206.     BOOL isPolar = [status isPolar];
  207.  
  208.     [status setAutoscaleCoord:(tag == Z_TAG)? (isPolar? R_TAG :Z_TAG) :tag
  209.                          isOn: [cell state]];
  210.  
  211.     [win = [view window] disableDisplay];
  212.     [self _updateRangeIsThreeD:[status isThreeD] isPolar:isPolar];
  213.     [rangeMatrix selectTextAt:tag :0];
  214.     [win reenableDisplay];
  215.     [rangeMatrix display];
  216.  
  217.     return self;
  218. }
  219.  
  220.  
  221.  
  222. - doSetLog:sender
  223. {
  224.     id cell = [sender selectedCell];
  225.     int tag = [cell tag];
  226.     BOOL state = [cell state];
  227.     BOOL isPolar = [status isPolar];
  228.     double min = [[rangeMatrix cellAt:tag :0] doubleValue];
  229.     double max = [[rangeMatrix cellAt:tag :1] doubleValue];
  230.  
  231.     if ( state && ((min <= 0) || (max <= 0)) )  {
  232.         NXRunAlertPanel ([stringSet valueForStringKey: "log"],
  233.                          [stringSet valueForStringKey: "logRange"],
  234.                          NULL, NULL, NULL);
  235.         [cell setState:0];
  236.         return nil;
  237.     } else
  238.         return [status setIsLogCoord:(tag == Z_TAG)? (isPolar?R_TAG:Z_TAG) :tag
  239.                               isOn:state];
  240. }
  241.  
  242.  
  243.  
  244. - doSetAngles:sender
  245. {
  246.     int tag = [sender selectedTag];
  247.  
  248.     if (tag != oldAnglesTag) {
  249.         [status setDegrees:tag == ANGLES_DEGREES];
  250.         [self _updateRangeIsThreeD:[status isThreeD] isPolar:[status isPolar]];
  251.         oldAnglesTag = tag;
  252.     }
  253.  
  254.     return self;
  255. }
  256.  
  257.  
  258.  
  259. - doSetLabel:sender
  260. {
  261.     id        cell = [sender selectedCell];
  262.     int        tag = [cell tag];
  263.  
  264.     [status setLabelCoord:tag to:[cell stringValue]];
  265.  
  266.     /* status might fix the label */
  267.     [cell setStringValue:[status labelCoord:tag]];
  268.  
  269.     return self;
  270. }
  271.  
  272.  
  273.  
  274. - doSetTics:sender
  275. {
  276.     TicCell *cell = [sender selectedCell];
  277.  
  278.     [status setTicsCoord:[cell tag] isOn:[cell state]];
  279.     [self _updateTicsIsThreeD:[status isThreeD]];
  280.  
  281.     return self;
  282. }
  283.  
  284.  
  285.  
  286. - doSetAxis:sender
  287. {
  288.     return [status setAxisCoord:[sender tag] on:[sender state]];
  289. }
  290.  
  291.  
  292.  
  293. - doSetGrid:sender
  294. {
  295.     return [status setGrid:[sender state]];
  296. }
  297.  
  298.  
  299.  
  300. - doSetTicsIn:sender
  301. {
  302.     return [status setTicsIn:([ticsInMatrix selectedTag] == 0)];
  303. }
  304.  
  305.  
  306.  
  307. - showTicOptionsPanel:sender
  308. {
  309.     if (!ticOptionsPanel)
  310.     ticOptionsPanel = [[TicOptionsPanel allocFromZone:[self zone]] init];
  311.     [ticOptionsPanel showPanel:self];
  312.     return self;
  313. }
  314.  
  315.  
  316.  
  317. - windowDidUpdate:sender
  318. {
  319.     return self;
  320. }
  321.  
  322.  
  323. // Shuts up the compiler about unused RCSId
  324. - (const char *) rcsid
  325. {
  326.     return RCSId;
  327. }
  328.  
  329.  
  330. @end
  331.  
  332.  
  333. @implementation AxesPane (Private)
  334.  
  335. - _updateLabelIsThreeD:(BOOL)isThreeD
  336. {
  337.     int i;
  338.  
  339.     for (i = 0 ; i < 3 ; i++)
  340.         [[labelMatrix findCellWithTag:i] setStringValue:[status labelCoord:i]];
  341.  
  342.     [[labelMatrix findCellWithTag:Z_TAG] setEnabled:isThreeD];
  343.     [[labelMatrixLabelMatrix findCellWithTag:Z_TAG]
  344.                  setTextGray:isThreeD? NX_BLACK: NX_DKGRAY];
  345.  
  346.     return self;
  347. }
  348.  
  349.  
  350.  
  351. - _updateTicsIsThreeD:(BOOL)isThreeD
  352. {
  353.     id cell;
  354.     BOOL ticsX = [status ticsCoord:X_TAG];
  355.     BOOL ticsY = [status ticsCoord:Y_TAG];
  356.     BOOL ticsZ = [status ticsCoord:Z_TAG];
  357.  
  358.     [ticsInMatrix selectCellWithTag: [status ticsIn]? 0: 1];
  359.     [ticsInMatrix setEnabled: (ticsX || ticsY || (ticsZ && isThreeD))];
  360.  
  361.     cell = [ticsMatrix findCellWithTag:X_TAG];
  362.     [cell setState:ticsX];
  363.  
  364.     cell = [ticsMatrix findCellWithTag:Y_TAG];
  365.     [cell setState:ticsY];
  366.  
  367.     cell = [ticsMatrix findCellWithTag:Z_TAG];
  368.     if (ticsZ)
  369.         [cell setState:ticsZ && isThreeD];
  370.     [cell setEnabled:isThreeD];
  371.  
  372.     [ticsMatrix display];
  373.  
  374.     return self;
  375. }
  376.  
  377.  
  378.  
  379. - _updateRangeIsThreeD:(BOOL)isThreeD isPolar:(BOOL)isPolar
  380. {
  381.     int state, i;
  382.     id    cell;
  383.                         /* Update X & Y Ranges */
  384.     for (i = 0 ; i <= 1 ; i++)  {
  385.     [[rangeAutoMatrix findCellWithTag:i] setState:
  386.                 state = [status autoscaleCoord:i]];
  387.     [cell = [rangeMatrix cellAt:i :0] setDoubleValue: [status minCoord:i]];
  388.     [cell setEnabled:!state];
  389.     [cell = [rangeMatrix cellAt:i :1] setDoubleValue: [status maxCoord:i]];
  390.     [cell setEnabled:!state];
  391.     }
  392.  
  393.  
  394.     /* 
  395.      *  We use the Z controls as R when the plot is polar.  In cases 
  396.      *  like this, the tag of the control will be Z_TAG, so it will 
  397.      *  seem to refer to a Z coordinate instead of an R coordinate.  
  398.      *  We need to be careful, here and elsewhere in Inspector, to 
  399.      *  deal with the control using Z_TAG and deal with Status 
  400.      *  settings using R_TAG if the plot is polar.
  401.      */
  402.     
  403.     i = isPolar? R_TAG :Z_TAG;
  404.     cell = [rangeAutoMatrix findCellWithTag:Z_TAG];
  405.     [cell setTitle:isPolar? "R     " :"Z     "];
  406.     [cell setState:state = [status autoscaleCoord:i]];
  407.     [cell setEnabled:isPolar || isThreeD];
  408.  
  409.     cell = [rangeMatrix cellAt:Z_TAG :0];
  410.     [cell setEnabled:!state && (isPolar || isThreeD)];
  411.     [cell setDoubleValue: [status minCoord:i]];
  412.  
  413.     cell = [rangeMatrix cellAt:Z_TAG :1];
  414.     [cell setEnabled:!state && (isPolar || isThreeD)];
  415.     [cell setDoubleValue: [status maxCoord:i]];
  416.  
  417.     [rangeMatrix display];
  418.     [rangeAutoMatrix display];
  419.  
  420.     return self;
  421. }
  422.  
  423.  
  424.  
  425. @end
  426.